cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(DeviceIo)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/include/DeviceIo DESTINATION ${CMAKE_INSTALL_STAGING}/usr/include/)
if(CPU_ARCH STREQUAL "arm")
	message("CPU_ARCH is ${CPU_ARCH}")
    if(BLUEZ)
        message("BLUETOOTH_BRANCH is BLUEZ")
        file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib32/libDeviceIo_bluez.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_bluez.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
    elseif(BSA)
        if(CYPRESS)
            message("BLUETOOTH_BRANCH is BSA:CYPRESS")
            file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib32/libDeviceIo_cypress.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
            file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_cypress.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
        elseif(BROADCOM)
            message("BLUETOOTH_BRANCH is BSA:BROADCOM")
            file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib32/libDeviceIo_broadcom.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
            file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_broadcom.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
        endif()
    endif()
endif()
if(CPU_ARCH STREQUAL "aarch64")
	message("CPU_ARCH is ${CPU_ARCH}")
    if(BLUEZ)
        message("BLUETOOTH_BRANCH is BLUEZ")
        file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib64/libDeviceIo_bluez.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_bluez.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
    elseif(BSA)
        if(CYPRESS)
            message("BLUETOOTH_BRANCH is BSA:CYPRESS")
            file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib64/libDeviceIo_cypress.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
            file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_cypress.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
        elseif(BROADCOM)
            message("BLUETOOTH_BRANCH is BSA:BROADCOM")
            file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lib64/libDeviceIo_broadcom.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/)
            file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/libDeviceIo_broadcom.so ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so)
        endif()
    endif()
endif()
install(FILES ${CMAKE_INSTALL_STAGING}/usr/lib/libDeviceIo.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib RENAME libDeviceIo.so)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/DeviceIo DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
